package pratice;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;

public class SendUDP {//定义发送端口
    public static void main(String[] args) throws Exception {//
        DatagramSocket  ds=new DatagramSocket();//创建发送对象
        byte[] bytes="陕西，西安".getBytes();//定义发送字节内容
        int length = bytes.length;//定义发送字节数据长度
                 int  port=10086;//
        InetAddress byName = InetAddress.getByName("192.168.29.59");
        //规定IP地址
        DatagramPacket  dp=new DatagramPacket(bytes,length,byName,port);
        //打包发送数据
        ds.send(dp);//发送数据
        ds.close();//关闭资源
    }
}
